/*
    backend for TimeTagger, an OpalKelly based single photon counting library
    Copyright (C) 2011  Markus Wick <wickmarkus@web.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef BACKEND_PULSED_H_
#define BACKEND_PULSED_H_

#include <list>

#include "TimeTagger.h"

struct _PulsedEdge {
	long long edge;
	int pulse;
};

class Pulsed : public _Iterator {
public:
	Pulsed(int _length, long long _binwidth, int _sequence_length, int _channel, int _shot_trigger=-1, int _sequence_trigger=-1);
	virtual ~Pulsed();

	virtual const char *getClassName();
	virtual const char *getScpiCommand();
	virtual std::string getScpiParameters();
	virtual void getMeta(long long **ARGOUTVIEWM_ARRAY2, int *DIM1);

	virtual void start();

	void getData(int **ARGOUTVIEWM_ARRAY2, int *DIM1, int *DIM2);
	void setMaxCounts(int c);
	int getCounts();
	bool ready();
	virtual void clear();

protected:

	virtual void next(Tag* list, int count, long long time);

private:
	int channel;
	int length, sequence_length;
	long long binwidth;
	int shot_trigger, sequence_trigger;

	int *data;

	std::list<_PulsedEdge> edge;

	bool waiting_for_sync;
	int pulse, counts, max_counts;

};

#endif /* PULSED_H_ */
